Page({

  /**
   * 页面的初始数据
   */
  data: {
    imgurl:'',
    params:{
      page: 1,
      size: 10,
      adultTypeName: ''
    },
    list: []
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    wx.setNavigationBarTitle({
      title: options.adultTypeName
    })
    
    this.setData({
      imgurl: options.imgurl,
      params: {
        page: 1,
        size: 10,
        adultTypeName: options.adultTypeName
      }
    })

    this.getList(this.data.params)
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {
    
  },


  //书本详情
  bookdetail(e) {
    console.log(e)


    // if (wx.getStorageSync('token') == '') {
    //   this.setData({
    //     istokenPop: true
    //   })
    //   return
    // }

    var bookId = e.currentTarget.dataset.bookid
    wx.navigateTo({
      url: '/package/index/pages/bookdetail/bookdetail?bookId=' + bookId,
    })
  },


  getList (params) {
  
    var _this = this
    wx.request({
      url: 'https://devapi.xiaoshitimebank.com/user/sdx/sdx/FirstPage/adult/findBookInfos',
      method: 'POST',
      data: params,
      header: {
        "content-type": "application/x-www-form-urlencoded; charset=UTF-8",
        "token": wx.getStorageSync('token'),
        "uid": wx.getStorageSync('uuid')
      },
      success: (res) => {
        if (res.data.code == 200) {
      
          _this.setData({
            total: res.data.count
          })

          var list = _this.data.list

          res.data.data.forEach(function (item, index) {
            list.push(item)
          })
          _this.setData({
            list: list
          })
        } else {
          wx.showToast({
            title: res.data.msg,
            icon: 'none'
          })
        }
      }
    })
  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {
    
  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {
    
  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {
    
  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {
    
  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {
    if (this.data.list.length != this.data.total) {
      this.data.params.page += 1
      this.getList(this.data.params)
    }
  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {
    var that = this;

    return {

      title: that.data.params.adultTypeName,

      path: '/package/index/pages/newTypelist/newTypelist?adultTypeName=' + that.data.params.adultTypeName + '&imgurl=' + that.data.imgurl,

      imageUrl: that.data.imgurl,
      success: function (res) {

        console.log("转发成功:" + JSON.stringify(res));

        wx.showToast({
          title: '转发成功',
          icon: 'none'
        })

        // that.shareClick();

      }
    }
  }
})